<template>
	<view :class="currentTheme">
		<a-nabbar name="设置价格" />
		<view class="u-padding-32">
			<!-- <item-box paddinglr="40"> -->
				<!-- <label-box label="剧本名称" labelWidth="130">
					<view style="line-height: 64rpx;">{{option.name}}</view>
				</label-box> -->
				<label-box label="价格" labelWidth="130">
					<view class="u-flex">
						<view class="u-flex-1">
							<u-input v-model="option.intoPayMoney" type="digit" :clearable="false"
							border placeholder="请输入价格" 
							:borderColor="currentThemeObj.inputBorderColor" 
							 :placeholder-style="`color:${currentThemeObj.placeholderColor}`"/>
						</view>
						<text class="u-margin-left-20 text-order-time">元/人</text>
					</view>
				</label-box>
				<!-- <label-box label="线上价格">
					<view class="u-flex">
						<view class="u-flex-1">
							<u-input v-model="option.onlineIntoPayMoney" type="digit" :clearable="false"
							border placeholder="请输入价格" 
							:borderColor="currentThemeObj.inputBorderColor" 
							 :placeholder-style="`color:${currentThemeObj.placeholderColor}`"/>
						</view>
						<text class="u-margin-left-20 text-order-time">元/人</text>
					</view>
				</label-box> -->
				<view v-if="!isBuy">
					<!-- <view class="u-padding-top-10 u-padding-bottom-10">
						<u-line color="rgba(111, 109, 120, 0.4)"></u-line>
					</view> -->
					<view class="u-flex u-col-top ">
						<view class="form-label">购买凭证</view>
						<view class="u-flex-1">
							<view class="u-flex u-col-top">
								<view class="u-flex-1">
									<uploader ref="image" max-count="6" :bgColor="currentThemeObj.backgroundSecondColor" :list="option.buyVoucher" @getImgStr="getBuyVoucher" @uploaded="getUpload"></uploader>
								</view>
							</view>
							<view class="text-color-9598a4 u-font-26 u-margin-top-20">最多可上传6张</view>
						</view>
					</view>
				</view>
			<!-- </item-box> -->
		</view>
		<fixed-team btnText="保存" @btnClick="save" :loading="loading"></fixed-team>
	</view>
</template>

<script>
	import {update,getDetail} from '@/api/crud.js'
	import uploader from '@/components/upload/upload.vue'
	import {mapGetters} from 'vuex'
	export default {
		components:{
			uploader
		},
		data() {
			return {
				apiModule:'shopApi',
				option:{
					intoPayMoney:"",
					buyVoucher:"",
					onlineIntoPayMoney:""
				},
				apiType:"product",
				name:'updateMoneyAndVoucher',
				intoPayMoney:'',
				isBuy:false, // 已购买该剧本
				loading:false
			};
		},
		onLoad(option) {
			this.option = option;
			getDetail({productId:option.id},this.apiType,this.apiModule,'findPlatformBuy').then(res=>{
				this.isBuy = res;
			})
		},
		methods:{
			save(){
				if(!this.option.intoPayMoney){
					this.$u.toast('请输入价格')
					return false;
				}
				// if(!this.option.onlineIntoPayMoney){
				// 	this.$u.toast('请输入线上价格')
				// 	return false;
				// }
				const {buyVoucher } = this.option;
				if(!buyVoucher&&!this.isBuy){
					this.$u.toast('请至少上传一张凭证图片')
					return false;
				}
				this.loading = true;
				update(this.option,this.apiType,this.apiModule,`${this.name}/${this.option.id}`).then(res=>{
					const txt = this.isBuy ? '新增成功' : '待管理员审核后显示该剧本'
					this.routeBack(txt);
					this.loading = false;
				}).catch(()=>{
					this.loading = false;
				})
			},
			//上传的图片
			getBuyVoucher(str){
				this.option.buyVoucher = str;
			},
			//监听上传图片
			getUpload(flag){
				this.uploadFlag = flag;
			},
		}
	}
</script>

<style lang="scss" scoped>
.save-btn{
	padding: 100rpx 0;
}
.form-label{
	width: 210rpx;
	color: white;
	font-size: 32rpx;
}
.btn-style{
	width: 260rpx;
	line-height: 70rpx;
	text-align: center;
	margin: 0 auto;
	height: 70rpx;
	border-radius: 50rpx;
	background-color: #765CFE;
	color: white;
}
</style>
